package com.evildog.workspace.security.jwt.config;

import com.evildog.workspace.security.jwt.prop.JwtProperties;
import com.evildog.workspace.security.jwt.util.JwtUtil;
import lombok.Data;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Data
@Configuration
public class JwtConfig {

    @Bean
    @ConfigurationProperties(prefix = "workspace.jwt")
    @ConditionalOnProperty(prefix = "workspace.jwt", value = "enable")
    public JwtProperties jwtProperties() {
        return new JwtProperties();
    }

    @Bean
    @ConditionalOnBean(JwtProperties.class)
    public JwtUtil jwtUtil(JwtProperties jwtProperties) {
        return new JwtUtil(jwtProperties);
    }
}
